package com.wjc.utils.log;

import java.util.Arrays;

import org.apache.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

@Aspect
public class LoggerAspect {

	@Around("within(com.wjc.service..*)")
	public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
		Logger logger = Logger.getLogger(joinPoint.getTarget().getClass());
		long startTime = System.currentTimeMillis();
		logger.info("Start executing method " + joinPoint.getSignature().getName() + " On "
				+ joinPoint.getTarget().getClass());
		logger.info("method arguments : " + Arrays.toString(joinPoint.getArgs()));
		Object obj = joinPoint.proceed(); // continue on the intercepted method

		long endTime = System.currentTimeMillis();
		logger.info("End executing method: " + joinPoint.getSignature().getName() + " Executed time : "
				+ (endTime - startTime));
		return obj;
	}
}
